



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class QuestionsAnswersDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public QuestionsAnswersDB()
        {
        }

        public QuestionsAnswersDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<QuestionsAnswers> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();

            string strQuery = " select " + strTop  + " * from dbo.[QuestionsAnswers]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    QuestionsAnswers obj = new QuestionsAnswers();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["QuestionsID"] != DBNull.Value)
                    {
                        obj.QuestionsID = (System.Int64)dr["QuestionsID"];
                    }
                    else
                    {
                        obj.QuestionsID = -1;
                    } 
 if (dr["AnswerAR"] != DBNull.Value)
                    {
                        obj.AnswerAR = (System.String)dr["AnswerAR"];
                    }
                    else
                    {
                        obj.AnswerAR = "";
                    } 
 if (dr["AnswerEN"] != DBNull.Value)
                    {
                        obj.AnswerEN = (System.String)dr["AnswerEN"];
                    }
                    else
                    {
                        obj.AnswerEN = "";
                    } 
 if (dr["IsAnswer"] != DBNull.Value)
                    {
                        obj.IsAnswer = (System.Boolean)dr["IsAnswer"];
                    }
                    else
                    {
                        obj.IsAnswer = false;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<QuestionsAnswers> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<QuestionsAnswers> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , QuestionsAnswers obj)
        {
            
            

                    DbParameter prmQuestionsID = con.createParameter();
                    prmQuestionsID.ParameterName = "@QuestionsID";
                    prmQuestionsID.DbType =DbType.Int64;
                    if (obj.QuestionsID == null)
                    {
                        prmQuestionsID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionsID.Value = obj.QuestionsID;
                    }
                

                    


                    DbParameter prmAnswerAR = con.createParameter();
                    prmAnswerAR.ParameterName = "@AnswerAR";
                    prmAnswerAR.DbType =DbType.String;
                    if (obj.AnswerAR == null)
                    {
                        prmAnswerAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAnswerAR.Value = obj.AnswerAR;
                    }
                

                    


                    DbParameter prmAnswerEN = con.createParameter();
                    prmAnswerEN.ParameterName = "@AnswerEN";
                    prmAnswerEN.DbType =DbType.String;
                    if (obj.AnswerEN == null)
                    {
                        prmAnswerEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAnswerEN.Value = obj.AnswerEN;
                    }
                

                    


                    DbParameter prmIsAnswer = con.createParameter();
                    prmIsAnswer.ParameterName = "@IsAnswer";
                    prmIsAnswer.DbType =DbType.Boolean;
                    if (obj.IsAnswer == null)
                    {
                        prmIsAnswer.Value = DBNull.Value;
                    }
                    else
                    {
                        prmIsAnswer.Value = obj.IsAnswer;
                    }
                

                    


           



            string strQuery = " insert into dbo.[QuestionsAnswers] ([QuestionsID],[AnswerAR],[AnswerEN],[IsAnswer]) VALUES (@QuestionsID,@AnswerAR,@AnswerEN,@IsAnswer) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmQuestionsID,prmAnswerAR,prmAnswerEN,prmIsAnswer);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(QuestionsAnswers obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, QuestionsAnswers obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmQuestionsID = con.createParameter();
                    prmQuestionsID.ParameterName = "@QuestionsID";
                    prmQuestionsID.DbType =DbType.Int64;
                    if (obj.QuestionsID == null)
                    {
                        prmQuestionsID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionsID.Value = obj.QuestionsID;
                    }
                

                    


                    DbParameter prmAnswerAR = con.createParameter();
                    prmAnswerAR.ParameterName = "@AnswerAR";
                    prmAnswerAR.DbType =DbType.String;
                    if (obj.AnswerAR == null)
                    {
                        prmAnswerAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAnswerAR.Value = obj.AnswerAR;
                    }
                

                    


                    DbParameter prmAnswerEN = con.createParameter();
                    prmAnswerEN.ParameterName = "@AnswerEN";
                    prmAnswerEN.DbType =DbType.String;
                    if (obj.AnswerEN == null)
                    {
                        prmAnswerEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAnswerEN.Value = obj.AnswerEN;
                    }
                

                    


                    DbParameter prmIsAnswer = con.createParameter();
                    prmIsAnswer.ParameterName = "@IsAnswer";
                    prmIsAnswer.DbType =DbType.Boolean;
                    if (obj.IsAnswer == null)
                    {
                        prmIsAnswer.Value = DBNull.Value;
                    }
                    else
                    {
                        prmIsAnswer.Value = obj.IsAnswer;
                    }
                

                    


           



            string strQuery = " update dbo.[QuestionsAnswers] set [QuestionsID]=@QuestionsID,[AnswerAR]=@AnswerAR,[AnswerEN]=@AnswerEN,[IsAnswer]=@IsAnswer where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmQuestionsID,prmAnswerAR,prmAnswerEN,prmIsAnswer);

            

        }


        public void Update(QuestionsAnswers obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, QuestionsAnswers obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[QuestionsAnswers]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( QuestionsAnswers obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<QuestionsAnswers> getQuestionsAnswersByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<QuestionsAnswers> getQuestionsAnswersByID(System.Int64 ID)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsAnswersByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<QuestionsAnswers> getQuestionsAnswersByQuestionsID(ClassDataHandler con,System.Int64 QuestionsID)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();


                        DbParameter prmQuestionsID = con.createParameter();
                        prmQuestionsID.ParameterName = "@QuestionsID";
                        prmQuestionsID.DbType = DbType.Int64;
                        if (QuestionsID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmQuestionsID.Value = QuestionsID;
                        }


                        lstRet = Select(con, "" , " where [QuestionsID]=@QuestionsID ", prmQuestionsID);



                        return lstRet;

                    }


                    public List<QuestionsAnswers> getQuestionsAnswersByQuestionsID(System.Int64 QuestionsID)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsAnswersByQuestionsID(con, QuestionsID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<QuestionsAnswers> getQuestionsAnswersByAnswerAR(ClassDataHandler con,System.String AnswerAR)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();


                        DbParameter prmAnswerAR = con.createParameter();
                        prmAnswerAR.ParameterName = "@AnswerAR";
                        prmAnswerAR.DbType = DbType.String;
                        if (AnswerAR == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmAnswerAR.Value = AnswerAR;
                        }


                        lstRet = Select(con, "" , " where [AnswerAR]=@AnswerAR ", prmAnswerAR);



                        return lstRet;

                    }


                    public List<QuestionsAnswers> getQuestionsAnswersByAnswerAR(System.String AnswerAR)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsAnswersByAnswerAR(con, AnswerAR);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<QuestionsAnswers> getQuestionsAnswersByAnswerEN(ClassDataHandler con,System.String AnswerEN)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();


                        DbParameter prmAnswerEN = con.createParameter();
                        prmAnswerEN.ParameterName = "@AnswerEN";
                        prmAnswerEN.DbType = DbType.String;
                        if (AnswerEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmAnswerEN.Value = AnswerEN;
                        }


                        lstRet = Select(con, "" , " where [AnswerEN]=@AnswerEN ", prmAnswerEN);



                        return lstRet;

                    }


                    public List<QuestionsAnswers> getQuestionsAnswersByAnswerEN(System.String AnswerEN)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsAnswersByAnswerEN(con, AnswerEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<QuestionsAnswers> getQuestionsAnswersByIsAnswer(ClassDataHandler con,System.Boolean IsAnswer)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();


                        DbParameter prmIsAnswer = con.createParameter();
                        prmIsAnswer.ParameterName = "@IsAnswer";
                        prmIsAnswer.DbType = DbType.Boolean;
                        if (IsAnswer == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmIsAnswer.Value = IsAnswer;
                        }


                        lstRet = Select(con, "" , " where [IsAnswer]=@IsAnswer ", prmIsAnswer);



                        return lstRet;

                    }


                    public List<QuestionsAnswers> getQuestionsAnswersByIsAnswer(System.Boolean IsAnswer)
                    {
                        List<QuestionsAnswers> lstRet = new List<QuestionsAnswers>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsAnswersByIsAnswer(con, IsAnswer);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<QuestionsAnswers> Search(ClassDataHandler con, QuestionsAnswers obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.QuestionsID != -1)
                    {
                        DbParameter prmQuestionsID = con.createParameter();
                        prmQuestionsID.ParameterName = "@QuestionsID";
                        prmQuestionsID.DbType =DbType.Int64;
                        if (obj.QuestionsID == null)
                        {
                            prmQuestionsID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionsID.Value = obj.QuestionsID;
                        }
                        strWhere += " [QuestionsID]=@QuestionsID AND ";
                        lstParameters.Add(prmQuestionsID);
                     }



                    

                    if (obj.AnswerAR != "")
                    {
                        DbParameter prmAnswerAR = con.createParameter();
                        prmAnswerAR.ParameterName = "@AnswerAR";
                        prmAnswerAR.DbType =DbType.String;
                        if (obj.AnswerAR == null)
                        {
                            prmAnswerAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAnswerAR.Value = obj.AnswerAR;
                        }
                        strWhere += " [AnswerAR]=@AnswerAR AND ";
                        lstParameters.Add(prmAnswerAR);
                     }



                    

                    if (obj.AnswerEN != "")
                    {
                        DbParameter prmAnswerEN = con.createParameter();
                        prmAnswerEN.ParameterName = "@AnswerEN";
                        prmAnswerEN.DbType =DbType.String;
                        if (obj.AnswerEN == null)
                        {
                            prmAnswerEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAnswerEN.Value = obj.AnswerEN;
                        }
                        strWhere += " [AnswerEN]=@AnswerEN AND ";
                        lstParameters.Add(prmAnswerEN);
                     }



                    

                    if (obj.IsAnswer != false)
                    {
                        DbParameter prmIsAnswer = con.createParameter();
                        prmIsAnswer.ParameterName = "@IsAnswer";
                        prmIsAnswer.DbType =DbType.Boolean;
                        if (obj.IsAnswer == null)
                        {
                            prmIsAnswer.Value = DBNull.Value;
                        }
                        else
                        {
                            prmIsAnswer.Value = obj.IsAnswer;
                        }
                        strWhere += " [IsAnswer]=@IsAnswer AND ";
                        lstParameters.Add(prmIsAnswer);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<QuestionsAnswers> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<QuestionsAnswers> Search(QuestionsAnswers obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<QuestionsAnswers> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<QuestionsAnswers> SearchOrLike(ClassDataHandler con, QuestionsAnswers obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.QuestionsID != -1)
                    {
                        DbParameter prmQuestionsID = con.createParameter();
                        prmQuestionsID.ParameterName = "@QuestionsID";
                        prmQuestionsID.DbType =DbType.Int64;
                        if (obj.QuestionsID == null)
                        {
                            prmQuestionsID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionsID.Value = obj.QuestionsID;
                        }
                        strWhere += " [QuestionsID]=@QuestionsID OR ";
                        lstParameters.Add(prmQuestionsID);
                     }



                    

                    if (obj.AnswerAR != "")
                    {
                        DbParameter prmAnswerAR = con.createParameter();
                        prmAnswerAR.ParameterName = "@AnswerAR";
                        prmAnswerAR.DbType =DbType.String;
                        if (obj.AnswerAR == null)
                        {
                            prmAnswerAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAnswerAR.Value = obj.AnswerAR;
                        }
                        strWhere += " [AnswerAR] LIKE @AnswerAR OR ";
                        lstParameters.Add(prmAnswerAR);
                     }



                    

                    if (obj.AnswerEN != "")
                    {
                        DbParameter prmAnswerEN = con.createParameter();
                        prmAnswerEN.ParameterName = "@AnswerEN";
                        prmAnswerEN.DbType =DbType.String;
                        if (obj.AnswerEN == null)
                        {
                            prmAnswerEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAnswerEN.Value = obj.AnswerEN;
                        }
                        strWhere += " [AnswerEN] LIKE @AnswerEN OR ";
                        lstParameters.Add(prmAnswerEN);
                     }



                    

                    if (obj.IsAnswer != false)
                    {
                        DbParameter prmIsAnswer = con.createParameter();
                        prmIsAnswer.ParameterName = "@IsAnswer";
                        prmIsAnswer.DbType =DbType.Boolean;
                        if (obj.IsAnswer == null)
                        {
                            prmIsAnswer.Value = DBNull.Value;
                        }
                        else
                        {
                            prmIsAnswer.Value = obj.IsAnswer;
                        }
                        strWhere += " [IsAnswer]=@IsAnswer OR ";
                        lstParameters.Add(prmIsAnswer);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<QuestionsAnswers> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<QuestionsAnswers> SearchOrLike(QuestionsAnswers obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<QuestionsAnswers> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            